package frame.laxcen.response;

import frame.laxcen.BaseFrame;
import frame.laxcen.exception.IllegalFrameFormatException;
import frame.laxcen.util.FrameReader;

import java.util.HashMap;
import java.util.Map;

public class Response_0010_11 extends BaseFrame implements IResponse {

    public Response_0010_11(BaseFrame baseFrame) throws IllegalFrameFormatException {

        initialize(baseFrame.FrameBytes);
    }

    public Response_0010_11(byte[] bytes) throws IllegalFrameFormatException {

        initialize(bytes);
    }

    @Override
    public Map<String, String> explainToMap() throws IllegalFrameFormatException {

        Map<String, String> result = new HashMap<>();

        try {

            FrameReader reader = new FrameReader(this);

            switch(reader.readU8()) {

                case 0x00: result.put("写入结果", "写入成功"); break;
                case 0x01: result.put("写入结果", "天线端口参数错误"); break;
                case 0x02: result.put("写入结果", "选择参数错误"); break;
                case 0x03: result.put("写入结果", "写入参数错误"); break;
                case 0x04: result.put("写入结果", "CRC 校验错误"); break;
                case 0x05: result.put("写入结果", "功率不足"); break;
                case 0x06: result.put("写入结果", "数据区溢出"); break;
                case 0x07: result.put("写入结果", "数据区被锁定"); break;
                case 0x08: result.put("写入结果", "访问密码错误"); break;
                case 0x09: result.put("写入结果", "其他标签错误"); break;
                case 0x0a: result.put("写入结果", "标签丢失"); break;
                case 0x0b: result.put("写入结果", "读写器发送指令错误"); break;
            }

            reader.readP16((byte) 0x01, (s) -> result.put("写入失败字地址", Integer.toHexString(s)));

        } catch (Exception e) {

            e.printStackTrace();

            throw new IllegalFrameFormatException(e.getMessage());
        }

        return result;
    }
}
